/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.tabbedproperties.section;

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;

import com.cea.papyrus.core.tabbedproperties.PropertyViewSection;
import com.cea.papyrus.tabbedproperties.composites.UseCasesComposite;
import com.cea.papyrus.umlutils.Classifier;

/**
 * Defines use cases section of classifiers.
 * 
 * @author Gilles Cannenterre
 * @since 20 nov. 06
 */
public class ClassifierUseCasesSection extends PropertyViewSection {
	
	/**
	 * The use cases composite.
	 */
	private UseCasesComposite useCasesComposite;
		
	/**
	 * Creates the controls.
	 * 
	 * @param tabbedPropertySheetPage the tabbed property sheet page
	 * @param parent the parent
	 */
	@Override
	public void createControls(Composite parent,
            TabbedPropertySheetPage tabbedPropertySheetPage) {
        super.createControls(parent, tabbedPropertySheetPage);

        parent.setLayout(new FormLayout());
		FormData data;
		
		data = new FormData();
		data.right = new FormAttachment(100, 0);
		data.left = new FormAttachment(0, 0);
		
		// table for Parameters
        useCasesComposite = new UseCasesComposite();
        useCasesComposite.createContent(parent, tabbedPropertySheetPage.getWidgetFactory());
        useCasesComposite.setLayoutData(data);
    }
    
	/**
	 * Refresh.
	 */
	@Override
	public void refresh() {
    	useCasesComposite.refresh();
    }

	/**
	 * Sets the input.
	 * 
	 * @param part the part
	 * @param selection the selection
	 */
	@Override
	public void setInput(IWorkbenchPart part, ISelection selection) {
        super.setInput(part, selection); 
    	if(umlElement instanceof org.eclipse.uml2.uml.Classifier) {
    		Classifier classifier = new Classifier((org.eclipse.uml2.uml.Classifier)umlElement);
    		useCasesComposite.setElement(classifier);
    	}       
    }
	
	
	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.core.ui.properties.tabbed.PropertyViewSection#dispose()
	 */
	/**
	 * 
	 */
	public void dispose(){
		super.dispose();
		if(useCasesComposite!=null)
			useCasesComposite.dispose();
	}
}